#!/usr/bin/env python
#_*_coding:utf-8_*_
# =================================
# Author    : snakecy
# Date      : 2020/11/4 0004 17:51
# File      : main
# =================================


from fcmbci import FcmDataProcessor, FcmVisualize, FcmSimulator
fcm = FcmDataProcessor()

# fcm.read_xlsx('unittests/test_cases/sample_test.xlsx', 'Matrix')
fcm.read_xlsx('usedata.xlsx', 'Matrix')

data_mat = fcm.data
print(data_mat)

fcm.gen_weights_mat(data_mat)
weights = fcm.causal_weights

print(weights)
weights.to_csv('weights.csv')

fcm.create_system(causal_weights=weights)

vis = FcmVisualize(fcm)
# vis.system_view(fcm.system, target=['C1'])
# vis.system_view(fcm.system, target=['OI1'])

# init = {'OI1' : 0.01, 'OI2' : 0.01, 'OI3' : 0.01, 'OI4' : 0.1, 'OI5' : 0.05, 'UA1' : 0.05, 'UA2' : 0.1, 'UA3' : 0.05, 'UA4' : 0.05, 'UA5' : 0.05, 'US1' : 0.05, 'US2' : 0.05, 'US3' : 0.05, 'US4' : 0.05, 'UP1' : 0.1, 'UP2' : 0.05, 'UP3' : 0.05, 'UP4' : 0.05, 'UP5' : 0.01, 'UP6' : 0.01}
#
# sim = FcmSimulator(init, fcm.causal_weights)

# vis.simulation_view(sim.scenarios, 'initial_state', nxData=fcm.system, network_view =True)

scenario_1_init = {'OI1' : 0.01, 'OI2' : 0.01, 'OI3' : 0.01, 'OI4' : 0.1, 'OI5' : 0.05, 'UA1' : 0.05, 'UA2' : 0.1, 'UA3' : 0.3, 'UA4' : 0.5, 'UA5' : 0.05, 'US1' : 0.05, 'US2' : 0.05, 'US3' : 0.05, 'US4' : 0.05, 'UP1' : 0.1, 'UP2' : 0.05, 'UP3' : 0.05, 'UP4' : 0.05, 'UP5' : 0.01, 'UP6' : 0.01}

sim = FcmSimulator(scenario_1_init, fcm.causal_weights)

# sim.test_scenario('scenario_1', {'UA1' : 0.3, 'UA2' : 0.5}, fcm.causal_weights)
sim.test_scenario('scenario_1', scenario_1_init, fcm.causal_weights)
vis.simulation_view(sim.scenarios, 'scenario_1', nxData=fcm.system, network_view =True, target=['UA1','UA2'])

# print(sim.scenarios)
sim.scenarios['initial_state'].to_csv('initial_state.csv')
sim.scenarios['scenario_1'].to_csv('scenario_1.csv')

